spacer
spacerLokken Logo
spacerLokken Binary Logo
spacer
spacer
spacer
spacer spacer spacer spacer
File Reader
Language:   Server Sided ASP - JavaScript
Author:   Jon Lokken
Date:   4-8-2005

Description:  
Using the ASP file system object to read a file.  This will even get virtual include files that are included in that file.  It does not render the file as ASP though.  It only does a read on the file and return a text string.

<%@ LANGUAGE="JavaScript" %>
<% Response.buffer=true %>
<%

objMyFSO= Server.CreateObject("Scripting.FileSystemObject");

/*
* This version of getPage returns a string of the page contents
* with no return characters in the page. This is for use in
* the side Menu Contents.
* Author: Jon Lokken - 4.8.2005
*/
function getPage(pathOfPage){
var serverPath = Server.MapPath(pathOfPage);
var doesFileExist = objMyFSO.FileExists(serverPath);

if(doesFileExist){
var pageTStream = objMyFSO.OpenTextFile(serverPath);
var pageContents = "";

while(! pageTStream.AtEndOfStream){
var temp = "" + pageTStream.Readline();

if(virtualInclude.test(temp)){
var temp2 = temp.replace(virtualBeg, "");
temp2 = temp2.replace(virtualEnd, "");
temp = temp.replace(virtualInclude, getPage(temp2));
}

pageContents = pageContents + temp + "";
}
return pageContents;
}
else{
return String("The page "+pathOfPage+" has been moved or deleted from the server.");
}
}
 

%>
 


Disclaimer:
Feel free to use this code I have written.  I only ask that you leave my name in the comments.  I take no responsibility for this code working, imply no warranty as to it's validity, and will not be held liable if you decide to try it.  I am only trying to help out others so they don't have to struggle with the same problems as me...

Associated Sites: Jon Lokken - http://www.jonlokken.com | Amy Lokken - http://www.amylokken.com | Isabel Lokken - http://www.isabellokken.com | Elizabeth Lokken - http://www.elizabethlokken.com | Lokken.us - http://www.lokken.us | Lokken.co - http://www.lokken.co | Lokken Consulting - http://www.lokkenconsulting.com
Author: Jon Lokken - http://www.lokken.net